﻿Imports log4net

Partial Class F05_Edit
    Inherits System.Web.UI.Page
    Dim fctr As String
    Dim product As String
    Dim pyear As String
    Dim sumid As String
    Dim vers As String

    Public eid1 As String
    Public eid2 As String
    Public eid3 As String
    Public eid4 As String
    Public eid5 As String
    Public eid6 As String
    Public eid7 As String
    Public scripttext As String

    Private Shared logger As ILog = LogManager.GetLogger("F05_Edit")

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("users") Is Nothing Then
            scripttext = "ClosePop();"
        End If
        Session.LCID = 2057
        fctr = Request("FCTR")
        product = Request("Product")
        pyear = Request("PlanYear")
        sumid = Request("sumid")
        vers = Request("version")


        Dim re_adap As New FormLockDSTableAdapters.FundCenterReleasesTableAdapter
        If re_adap.CountRelease(Val(pyear), vers, fctr) > 0 Then
            SaveDocument.Visible = False
        End If


        If IsPostBack = False Then
            scripttext = "CalSum();"
            If Val(sumid) = 1 Then
                Label1.Text = "บุคคลค้ำประกัน"
            Else
                Label1.Text = "หลักทรัพย์ค้ำประกัน"
            End If

            Dim fctr_adap As New FundCenterDSTableAdapters.FundCentersTableAdapter
            Dim fctr_name As String = ""
            fctr_name = fctr_adap.GetName(fctr, Val(pyear))

            Dim prod_adap As New BasicDataTableAdapters.ProductsTableAdapter
            Dim prod_name As String = ""
            prod_name = prod_adap.Getname(product, Val(pyear))
            Label2.Text = fctr_name
            Label2.Text += " - " & prod_name

            Dim f05adap As New F05_DSTableAdapters.F05_EditTableAdapter
            Dim f05dt As New F05_DS.F05_EditDataTable

            Dim sql = ""

            sql += " SELECT F05_1.Id AS Id, F05_2.Id AS id2, F05_1.PlanYear , F05_1.Version "
            sql += " , F05_1.Element1, F05_1.Element2, F05_1.Element3, F05_1.Element4, F05_1.Amount "
            sql += " , F05_2.Element3 AS Element2_3, F05_2.Element4 AS Element2_4, F05_2.Amount AS Amount2 "
            sql += " , F05_1.FormId , F05_1.FundCenter_FundCenterCode, F05_1.Cmmt_CmmtCode "
            sql += " , F05_2.Cmmt_CmmtCode AS Cmmt_CmmtCode2, F05_1.Product_ProductCode, F05_1.ProductItemNo "
            sql += " , F05_1.ProductItemDesc  "
            sql += " FROM F05_1 INNER JOIN F05_2 ON F05_1.ProductItemNo = F05_2.ProductItemNo "
            sql += " WHERE 1 = 1 "
            sql += " AND F05_1.FundCenter_FundCenterCode = '" & fctr & "' "
            sql += " AND F05_1.Product_ProductCode = '" & product & "' "
            sql += " AND F05_1.PlanYear = " & pyear
            sql += " AND F05_1.Version = '" & vers & "' "
            If Val(sumid) = 1 Then
                sql += " AND (ABS(F05_1.ProductItemNo) % 2) = 0 "
            Else
                sql += " AND (ABS(F05_1.ProductItemNo) % 2) <> 0 "
            End If

            sql += " AND F05_2.FundCenter_FundCenterCode = '" & fctr & "'"
            sql += " AND F05_2.Product_ProductCode = '" & product & "'"
            sql += " AND F05_2.PlanYear = " & pyear
            sql += " AND F05_2.Version = '" & vers & "' "
            If Val(sumid) = 1 Then
                sql += " AND (ABS(F05_2.ProductItemNo) % 2) = 0 "
            Else
                sql += " AND (ABS(F05_2.ProductItemNo) % 2) <> 0 "
            End If
            'Response.Write(sql)
            f05adap.GetDataByFilter(f05dt, sql)
            Dim adap2 As New F05_DSTableAdapters.BudgetDetailsTableAdapter
            'Response.Write(sql)
            For Each row As F05_DS.F05_EditRow In f05dt

                If Val(sumid) = 1 Then
                    Select Case Val(row.ProductItemNo)
                        Case 2
                            E1_ID.Text = row.Id
                            E1_ID2.Text = row.id2
                            E1_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E1_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E1_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E1_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E1_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E1_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E1_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E1_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach1.Text = adap2.GetAttachAmount(row.Id)
                            eid1 = row.Id
                        Case 4
                            E2_ID.Text = row.Id
                            E2_ID2.Text = row.id2
                            E2_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E2_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E2_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E2_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E2_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E2_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E2_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E2_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach2.Text = adap2.GetAttachAmount(row.Id)
                            eid2 = row.Id
                        Case 6
                            E3_ID.Text = row.Id
                            E3_ID2.Text = row.id2
                            E3_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E3_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E3_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E3_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E3_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E3_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E3_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E3_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach3.Text = adap2.GetAttachAmount(row.Id)
                            eid3 = row.Id
                        Case 8
                            E4_ID.Text = row.Id
                            E4_ID2.Text = row.id2
                            E4_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E4_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E4_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E4_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E4_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E4_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E4_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E4_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach4.Text = adap2.GetAttachAmount(row.Id)
                            eid4 = row.Id
                        Case 10
                            E5_ID.Text = row.Id
                            E5_ID2.Text = row.id2
                            E5_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E5_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E5_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E5_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E5_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E5_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E5_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E5_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach5.Text = adap2.GetAttachAmount(row.Id)
                            eid5 = row.Id
                        Case 12
                            E6_ID.Text = row.Id
                            E6_ID2.Text = row.id2
                            E6_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E6_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E6_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E6_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E6_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E6_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E6_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E6_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach6.Text = adap2.GetAttachAmount(row.Id)
                            eid6 = row.Id
                        Case 14
                            E7_ID.Text = row.Id
                            E7_ID2.Text = row.id2
                            E7_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E7_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E7_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E7_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E7_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E7_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E7_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E7_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach7.Text = adap2.GetAttachAmount(row.Id)
                            eid7 = row.Id
                    End Select

                Else
                    Select Case Val(row.ProductItemNo)
                        Case 1
                            E1_ID.Text = row.Id
                            E1_ID2.Text = row.id2
                            E1_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E1_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E1_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E1_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E1_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E1_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E1_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E1_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach1.Text = adap2.GetAttachAmount(row.Id)
                            eid1 = row.Id
                        Case 3
                            E2_ID.Text = row.Id
                            E2_ID2.Text = row.id2
                            E2_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E2_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E2_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E2_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E2_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E2_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E2_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E2_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach2.Text = adap2.GetAttachAmount(row.Id)
                            eid2 = row.Id
                        Case 5
                            E3_ID.Text = row.Id
                            E3_ID2.Text = row.id2
                            E3_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E3_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E3_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E3_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E3_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E3_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E3_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E3_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach3.Text = adap2.GetAttachAmount(row.Id)
                            eid3 = row.Id
                        Case 7
                            E4_ID.Text = row.Id
                            E4_ID2.Text = row.id2
                            E4_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E4_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E4_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E4_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E4_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E4_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E4_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E4_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach4.Text = adap2.GetAttachAmount(row.Id)
                            eid4 = row.Id
                        Case 9
                            E5_ID.Text = row.Id
                            E5_ID2.Text = row.id2
                            E5_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E5_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E5_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E5_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E5_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E5_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E5_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E5_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach5.Text = adap2.GetAttachAmount(row.Id)
                            eid5 = row.Id
                        Case 11
                            E6_ID.Text = row.Id
                            E6_ID2.Text = row.id2
                            E6_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E6_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E6_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E6_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E6_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E6_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E6_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E6_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach6.Text = adap2.GetAttachAmount(row.Id)
                            eid6 = row.Id
                        Case 13
                            E7_ID.Text = row.Id
                            E7_ID2.Text = row.id2
                            E7_1.Value = Format(Math.Abs(row.Element1), "#,##0.##")
                            E7_2.Value = Format(Math.Abs(row.Element2), "#,##0.##")
                            E7_3.Value = Format(Math.Abs(row.Element3), "#,##0.##")
                            E7_4.Value = Format(Math.Abs(row.Element4), "#,##0.##")
                            E7_5.Value = Format(Math.Abs(row.Amount), "#,##0.##")
                            E7_6.Value = Format(Math.Abs(row.Element2_3), "#,##0.##")
                            E7_7.Value = Format(Math.Abs(row.Element2_4), "#,##0.##")
                            E7_8.Value = Format(Math.Abs(row.Amount2), "#,##0.##")
                            Attach7.Text = adap2.GetAttachAmount(row.Id)
                            eid7 = row.Id
                    End Select

                End If

            Next

        Else
            eid1 = E1_ID.Text
            eid2 = E2_ID.Text
            eid3 = E3_ID.Text
            eid4 = E4_ID.Text
            eid5 = E5_ID.Text
            eid6 = E6_ID.Text
            eid7 = E7_ID.Text
        End If
    End Sub

    Protected Sub SaveDocument_Click(sender As Object, e As EventArgs) Handles SaveDocument.Click
        Dim errortext As String = ""
        Dim errcount As Integer = 0

        If Val(CStr(E1_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E1_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E1_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E1_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E1_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E1_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E1_1.Value).Replace(",", "")) = 0 Then
                errortext += "อยู่ระหว่างทวงถาม (ติดตามหนี้) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E1_2.Value).Replace(",", "")) = 0 Then
                errortext += "อยู่ระหว่างทวงถาม (ติดตามหนี้) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E2_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E2_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E2_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E2_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E2_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E2_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E2_1.Value).Replace(",", "")) = 0 Then
                errortext += "มีเลขคดีดำแล้ว (ฟ้องคดี) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E2_2.Value).Replace(",", "")) = 0 Then
                errortext += "มีเลขคดีดำแล้ว (ฟ้องคดี) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E3_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E3_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E3_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E3_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E3_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E3_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E3_1.Value).Replace(",", "")) = 0 Then
                errortext += "มีเลขคดีแดงแล้ว (พิพากษา) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E3_2.Value).Replace(",", "")) = 0 Then
                errortext += "มีเลขคดีแดงแล้ว (พิพากษา) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E4_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E4_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E4_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E4_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E4_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E4_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E4_1.Value).Replace(",", "")) = 0 Then
                errortext += "มีวันที่ยึดทรัพย์ (ยึดทรัพย์/สืบทรัพย์) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E4_2.Value).Replace(",", "")) = 0 Then
                errortext += "มีวันที่ยึดทรัพย์ (ยึดทรัพย์/สืบทรัพย์) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E5_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E5_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E5_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E5_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E5_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E5_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E5_1.Value).Replace(",", "")) = 0 Then
                errortext += "มีวันนัดขายทอดตลาดแล้ว (อยู่ระหว่างขายทอดตลาด) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E5_2.Value).Replace(",", "")) = 0 Then
                errortext += "มีวันนัดขายทอดตลาดแล้ว (อยู่ระหว่างขายทอดตลาด) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E6_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E6_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E6_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E6_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E6_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E6_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E6_1.Value).Replace(",", "")) = 0 Then
                errortext += "มีผู้ซื้อทรัพย์ได้แล้ว (ขายทอดตลาดได้แล้ว/รอรับเงิน) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E6_2.Value).Replace(",", "")) = 0 Then
                errortext += "มีผู้ซื้อทรัพย์ได้แล้ว (ขายทอดตลาดได้แล้ว/รอรับเงิน) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E7_1.Value).Replace(",", "")) <> 0 Or Val(CStr(E7_2.Value).Replace(",", "")) <> 0 Or Val(CStr(E7_3.Value).Replace(",", "")) <> 0 Or Val(CStr(E7_4.Value).Replace(",", "")) <> 0 Or Val(CStr(E7_6.Value).Replace(",", "")) <> 0 Or Val(CStr(E7_7.Value).Replace(",", "")) <> 0 Then
            If Val(CStr(E7_1.Value).Replace(",", "")) = 0 Then
                errortext += "ได้บัญชีรับจ่ายแล้ว (ผลสืบทรัพย์ / รอตัดหนี้สูญ) \n ● โปรดระบุจำนวนราย \n"
                errcount += 1
            End If
            If Val(CStr(E7_2.Value).Replace(",", "")) = 0 Then
                errortext += "ได้บัญชีรับจ่ายแล้ว (ผลสืบทรัพย์ / รอตัดหนี้สูญ) \n ● โปรดระบุเงินต้น \n"
                errcount += 1
            End If

        End If

        If Val(CStr(E1_1.Value).Replace(",", "")) < Val(CStr(E1_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> อยู่ระหว่างทวงถาม (ติดตามหนี้) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E1_1.Value).Replace(",", "")) < Val(CStr(E1_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> อยู่ระหว่างทวงถาม (ติดตามหนี้) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E2_1.Value).Replace(",", "")) < Val(CStr(E2_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> มีเลขคดีดำแล้ว (ฟ้องคดี) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E2_1.Value).Replace(",", "")) < Val(CStr(E2_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> มีเลขคดีดำแล้ว (ฟ้องคดี) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E3_1.Value).Replace(",", "")) < Val(CStr(E3_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> มีเลขคดีแดงแล้ว (พิพากษา) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E3_1.Value).Replace(",", "")) < Val(CStr(E3_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> มีเลขคดีแดงแล้ว (พิพากษา) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E4_1.Value).Replace(",", "")) < Val(CStr(E4_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> มีวันที่ยึดทรัพย์ (ยึดทรัพย์/สืบทรัพย์) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E4_1.Value).Replace(",", "")) < Val(CStr(E4_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> มีวันที่ยึดทรัพย์ (ยึดทรัพย์/สืบทรัพย์) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E5_1.Value).Replace(",", "")) < Val(CStr(E5_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> มีวันนัดขายทอดตลาดแล้ว (อยู่ระหว่างขายทอดตลาด) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E5_1.Value).Replace(",", "")) < Val(CStr(E5_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> มีวันนัดขายทอดตลาดแล้ว (อยู่ระหว่างขายทอดตลาด) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E6_1.Value).Replace(",", "")) < Val(CStr(E6_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> มีผู้ซื้อทรัพย์ได้แล้ว (ขายทอดตลาดได้แล้ว/รอรับเงิน) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E6_1.Value).Replace(",", "")) < Val(CStr(E6_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าจ้างทนายความ >> มีผู้ซื้อทรัพย์ได้แล้ว (ขายทอดตลาดได้แล้ว/รอรับเงิน) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If Val(CStr(E7_1.Value).Replace(",", "")) < Val(CStr(E7_3.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> ได้บัญชีรับจ่ายแล้ว (ผลสืบทรัพย์ / รอตัดหนี้สูญ) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If
        If Val(CStr(E7_1.Value).Replace(",", "")) < Val(CStr(E7_6.Value).Replace(",", "")) Then
            errortext += "ประมาณการค่าใช้จ่ายดำเนินคดี >> ได้บัญชีรับจ่ายแล้ว (ผลสืบทรัพย์ / รอตัดหนี้สูญ) \n ● จำนวนรายไม่ถูกต้อง \n"
            errcount += 1
        End If

        If (Val(CStr(S5.Value).Replace(",", "")) + Val(CStr(S8.Value).Replace(",", ""))) <= 0 Then
            errortext += "จำนวนเงินรวมไม่ถูกต้อง \n"
            errcount += 1
        End If

        If errcount Then
            errortext += "\n กรุณาแก้ไข"
            scripttext = "alert('" & errortext & "');"
            Exit Sub
        End If
        Dim adap As New F05_DSTableAdapters.BudgetDetailsTableAdapter
        Dim adapter12 As New SplitData2TableAdapters.Budget12TableAdapter
        Try

            adap.UpdateF05(Val(CStr(E1_1.Value).Replace(",", "")), Val(CStr(E1_2.Value).Replace(",", "")), Val(CStr(E1_3.Value).Replace(",", "")), Val(CStr(E1_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E1_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E1_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E1_6.Value).Replace(",", "")), Val(CStr(E1_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E1_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E1_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E2_1.Value).Replace(",", "")), Val(CStr(E2_2.Value).Replace(",", "")), Val(CStr(E2_3.Value).Replace(",", "")), Val(CStr(E2_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E2_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E2_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E2_6.Value).Replace(",", "")), Val(CStr(E2_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E2_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E2_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E3_1.Value).Replace(",", "")), Val(CStr(E3_2.Value).Replace(",", "")), Val(CStr(E3_3.Value).Replace(",", "")), Val(CStr(E3_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E3_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E3_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E3_6.Value).Replace(",", "")), Val(CStr(E3_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E3_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E3_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E4_1.Value).Replace(",", "")), Val(CStr(E4_2.Value).Replace(",", "")), Val(CStr(E4_3.Value).Replace(",", "")), Val(CStr(E4_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E4_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E4_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E4_6.Value).Replace(",", "")), Val(CStr(E4_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E4_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E4_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E5_1.Value).Replace(",", "")), Val(CStr(E5_2.Value).Replace(",", "")), Val(CStr(E5_3.Value).Replace(",", "")), Val(CStr(E5_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E5_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E5_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E5_6.Value).Replace(",", "")), Val(CStr(E5_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E5_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E5_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E6_1.Value).Replace(",", "")), Val(CStr(E6_2.Value).Replace(",", "")), Val(CStr(E6_3.Value).Replace(",", "")), Val(CStr(E6_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E6_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E6_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E6_6.Value).Replace(",", "")), Val(CStr(E6_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E6_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E6_ID2.Text).Replace(",", "")))

            adap.UpdateF05(Val(CStr(E7_1.Value).Replace(",", "")), Val(CStr(E7_2.Value).Replace(",", "")), Val(CStr(E7_3.Value).Replace(",", "")), Val(CStr(E7_4.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E7_5.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E7_ID.Text).Replace(",", "")))
            adap.UpdateF05(Nothing, Nothing, Val(CStr(E7_6.Value).Replace(",", "")), Val(CStr(E7_7.Value).Replace(",", "")), Nothing, Nothing, Nothing, Nothing, Nothing, Val(CStr(E7_8.Value).Replace(",", "")), Date.Now, Session("users"), Val(CStr(E7_ID2.Text).Replace(",", "")))


            adapter12.DeleteBID(Val(E1_ID.Text))
            adapter12.DeleteBID(Val(E1_ID2.Text))
            adapter12.DeleteBID(Val(E2_ID.Text))
            adapter12.DeleteBID(Val(E2_ID2.Text))
            adapter12.DeleteBID(Val(E3_ID.Text))
            adapter12.DeleteBID(Val(E3_ID2.Text))
            adapter12.DeleteBID(Val(E4_ID.Text))
            adapter12.DeleteBID(Val(E4_ID2.Text))
            adapter12.DeleteBID(Val(E5_ID.Text))
            adapter12.DeleteBID(Val(E5_ID2.Text))
            adapter12.DeleteBID(Val(E6_ID.Text))
            adapter12.DeleteBID(Val(E6_ID2.Text))
            adapter12.DeleteBID(Val(E7_ID.Text))
            adapter12.DeleteBID(Val(E7_ID2.Text))

            logger.Info("User " & Session("users") & " update product")

            scripttext = "ClosePop();"
        Catch ex As Exception
            scripttext = "alert('ไม่สามารถบันทึกได้เนื่องจากจำนวนเงินเกินค่าที่ระบบจะรับได้');"
        End Try
    End Sub
End Class
